<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/10/11
  Time: 10:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Title</title>
</head>
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css" media="all">
<style>
    body{
        background-color: rgb(242,242,242);
        padding: 15px;
    }
    .div-content{
        background-color: white;
        border-radius: 10px;
        padding: 15px;
    }
    fieldset{
        margin: 0;
        border: 1px solid #e6e6e6;
        padding: 10px 20px 5px 20px;
        color: #6b6b6b;
        border-radius: 10px;
    }
</style>
<body>
<script src="${pageContext.request.contextPath}/static/layui/layui.js" charset="utf-8"></script>

<form  class="layui-form" lay-filter="dataform" id="dataform" method="post">
    <input type="hidden" name="orderId" value="${order.orderId}" />
    <div class="layui-form-item">
        <label class="layui-form-label">房间号</label>
        <div class="layui-input-block">
            <input type="text" name="room.roomNum" value="${room.roomNum}" readonly autocomplete="off" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">开始时间</label>
        <div class="layui-input-block">
            <input type="text" name="detail.startTime" value="<fmt:formatDate value='${detail.startTime}' pattern='yyyy-MM-dd HH:mm:ss'/>" required  autocomplete="off" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">结束时间</label>
        <div class="layui-input-block">
            <input type="text" name="detail.deadTime" value="<fmt:formatDate value='${detail.deadTime}' pattern='yyyy-MM-dd HH:mm:ss'/>" required  autocomplete="off" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">订单日期</label>
        <div class="layui-input-block">
            <input type="text" name="orderDate" value="<fmt:formatDate value='${order.orderDate}' pattern='yyyy-MM-dd HH:mm:ss'/>" readonly  autocomplete="off" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">订单价格</label>
        <div class="layui-input-block">
            <input type="text" name="room.roomPrice" value="${room.roomPrice}" readonly  autocomplete="off" class="layui-input"/>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit=""
                    lay-filter="dosubmit" id="dosubmit">修改</button>
            <button type="submit" class="layui-btn" lay-submit=""
                    lay-filter="pay" id="pay">支付</button>
            <button type="submit" class="layui-btn" lay-submit=""
                    lay-filter="back" id="back">取消订单</button>
        </div>
    </div>
</form>
<script>
    layui.use([ "element", "jquery", "layer", "form", "table" ], function(){
        
        var $ = layui.$;
        var form = layui.form;

        form.on('submit(dosubmit)',function (data) {
            let url='${pageContext.request.contextPath}/updateById'
            $.post(url,data.field,function (response) {
                if(response.code==0){
                    layer.msg('修改成功',{
                        icon:1,
                        time:2000
                    },function () {
                        var index=parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.reload()
                    })
                }else {
                    alert('失败')
                }
            })
            return false;
        });

        //支付事件
        form.on('submit(pay)',function (obj) {
            var r=confirm("确定支付${room.roomPrice}元吗?");
            var orderId=${order.orderId};
            if (r==true) {
                $.ajax({
                    type:'get',
                    url:'${pageContext.request.contextPath}/findByOrderId',
                    data:'orderId='+orderId,
                    success:function (data) {
                        if (data==1){
                            $.ajax({
                                type:'post',
                                url:'${pageContext.request.contextPath}/changeState',
                                data:'orderId='+orderId,
                                success:function (d) {
                                    alert('修改成功！')
                                    var index=parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    parent.reload()
                                }
                            })
                        }else {
                            alert('已支付,无需在支付！')
                            var index=parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            parent.reload()
                        }
                    }

                })
            } else {
                alert('已取消该次操作！')
                var index=parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
                parent.reload()
            }
        })

        //取消订单事件
        form.on('submit(back)',function (obj){
            var w=confirm("确定取消订单吗?");
            var orderId=${order.orderId};
            if(w==true){
                $.ajax({
                    type:'post',
                    url:'${pageContext.request.contextPath}/findByOrderId1',
                    data:'orderId='+orderId,
                    success:function (data) {
                        if (data==1){
                            $.ajax({
                                type:'post',
                                url:'${pageContext.request.contextPath}/changeState1',
                                data:'orderId='+orderId,
                                success:function (d) {
                                    alert('修改成功！')
                                    var index=parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    parent.reload()
                                }
                            })
                        }else {
                            alert('未支付，无法取消！')
                            var index=parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            parent.reload()
                        }
                    }
                })
            }else {
                alert('已取消该次操作！')
                var index=parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
                parent.reload()
            }


        })

    });
</script>
</body>
</html>
